package com.xnchat.pro.dataStructure;

/**
 * @author wo
 */
public class MyQueue {
    private Node head;//头部
    private Node tail;//尾部

    private static class Node{
        private String value;//存放值
        private Node nextNode;//下个节点
        private Node previousNode;//上个节点

        public Node(String value, Node nextNode, Node previousNode) {
            this.value = value;
            this.nextNode = nextNode;
            this.previousNode = previousNode;
        }
    }
    //poll(offer)
    public void offer(String value){
        Node node = new Node(value, null, null);
        if (tail == null){
            head = tail = node;
        }else {
            tail.nextNode = node;
            tail = node;
        }
    }
    //remove(poll)
    public String poll(){
        if(head==null){
            return null;
        }
        Node h = head;
        head=head.nextNode;
        h.nextNode=null;
        if (head == null){
            tail = null;
        }
        return h.value;
    }
    //peek()
    public String peek(){
        return head == null ? null : head.value;
    }
    //size()

}
